<?php

set_time_limit(600);
ignore_user_abort(true);

require_once 'inc/common.php';
$time = time();

if (empty($_SESSION['updating']) || $time - $_SESSION['updating'] >= 600) {
	$_SESSION['updating'] = $time;
	session_write_close();

	$fb->destroySession(); // Force retrieval of new access token
	file_get_contents(WEB_URL . 'update_data.php?u=' . $_SESSION['me']['fbid']);
	
	session_start();
	$_SESSION['me'] = $db->qr('SELECT *, UNIX_TIMESTAMP(date_updated) AS unix_date_updated FROM users WHERE fbid = ?', $_SESSION['me']['fbid']);
	$_SESSION['updating'] = null;
	echo 'OK';
} else {
	echo 'NO';
}

?>